package com.myapp.ruyixing.http;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.myapp.ruyixing.model.MyFavoriteList;
import com.myapp.ruyixing.model.MyFavoriteList.Favorite;

public class MyFavoriteListParser extends RYJSONParser {
	@Override
	public Object parse(JSONObject jsonObject) {
		MyFavoriteList list = new MyFavoriteList();

		ListModelParser.parseListModel(list, jsonObject);
		JSONObject data = jsonObject.optJSONObject("data");
		JSONArray array = data.optJSONArray("items");
		list.items = new ArrayList<Favorite>();
		for (int i = 0; array != null && i < array.length(); i++) {
			JSONObject object = array.optJSONObject(i);
			if (object != null) {
				Favorite item = new Favorite();
				item.keywords = object.optString("keywords", "");
				item.score = object.optInt("score", 0);
				item.price = object.optString("price", "");
				item.title = object.optString("title", "");
				item.shopid = object.optString("shopid", "");
				item.picurl = object.optString("picurl", "");
				item.type = object.optString("type", "shop");
				list.items.add(item);
			}
		}

		return list;

	}
}
